﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Leo.Entities;
using Leo.BL;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;


namespace VeterinariaDrLeo.Controllers
{
    public class DetalleCompraController : Controller
    {
        //
        // GET: /DetalleCompra/
        [Dependency]
        public IDetalleCompraBL DetalleCompraBL { get; set; }

        public ActionResult Index()
        {
            var ListarDetalleCompra = DetalleCompraBL.GetFromDetComprasByCriterio("");
            return View(ListarDetalleCompra);
        }
        [HttpPost]
        public ActionResult Index(string criterio = "")
        {
            var detalleCompra = DetalleCompraBL.GetFromDetComprasByCriterio(criterio);
            return View(detalleCompra);
        }
        
        public ActionResult Create()
        {
            
            return View();
        }

        [HttpPost]
        public ActionResult Create(DetalleCompra detalleCompra)
        {

            try
            {
                // TODO: Add insert logic here

                DetalleCompraBL.AddDetalleCompra(detalleCompra);

                return RedirectToAction("index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Edit(int id)
        {
            var EditDetalleCompra = DetalleCompraBL.GetFromCompraByID(id);
            return View(EditDetalleCompra);
        }
        [HttpPost]
        public ActionResult Edit(int id, DetalleCompra detalleCompra)
        {
            try
            {
                // TODO: Add update logic here
                DetalleCompraBL.UpdateDetalleCompra(detalleCompra);

                return RedirectToAction("index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Delete(int id)
        {
            DetalleCompraBL.RemoveDetalleCompra(id);
            return RedirectToAction("index");
        }
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("index");
            }
            catch
            {
                return View();
            }
        }
        

    }
}
